<template>
  <div class="vip-list-container">

    <!-- 搜索选项 -->
    <div class="vip-list-top">
      <el-row>
        <el-col :span="5">
          <div class="vip-list-top-col">
            <span style="padding:0 5px">团长名称</span>
            <el-input v-model="leader_name" placeholder="请输入" size="small"></el-input>
          </div>
        </el-col>
        <el-col :span="7">
          <div class="order-manage-top-col" style="padding-left:0">
            <el-date-picker style="width:100%"
              v-model="time"
              type="datetimerange"
              range-separator="至"
              start-placeholde="开始时间"
              end-placeholde="结束时间"
              size="small">
            </el-date-picker>
          </div>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" size="small" @click="search">搜索</el-button>
        </el-col>
        <el-col :span="2" style="float: right">
          <a @click="export_data" v-bind:href="export_url" target="_blank">导出</a>
        </el-col>
      </el-row>
    </div>

    <!-- 表格 -->
    <div>
      <el-table :data="list" style="width:100%" stripe>
        <el-table-column prop="leader_uid" label="团长id" align="center" width="80px"></el-table-column>
        <el-table-column label="团长头像" align="center">
          <template slot-scope="scope" width="80px">
            <l-pic :picurl="scope.row.avatar" :size="{width:40,height:40}" :disdel="false" :disview="false"/>
          </template>
        </el-table-column>
        <el-table-column prop="nickname" label="昵称" align="center"></el-table-column>
        <el-table-column prop="area_name" label="小区名称" align="center"></el-table-column>
        <el-table-column prop="total_money" label="交易额" align="center"></el-table-column>
        <el-table-column prop="total" label="订单量" align="center"></el-table-column>
        <el-table-column prop="remain_money" label="消费佣金" align="center"></el-table-column>
        <el-table-column prop="express_price" label="运费" align="center"></el-table-column>
        <el-table-column prop="refund_money" label="退款" align="center"></el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div style="text-align:right;margin:15px 15px">
      <el-pagination class="page"
        background
        layout="total, prev, pager, next, jumper"
        :total="count"
        :page-size="10"
        :current-page="page"
        @size-change="changePage"
        @current-change="changePage">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getLeaderSales } from '@/api/statistics'
import LPic from '@/components/lPic'
import { parseTime } from '@/utils/index'

export default {
  name: 'vipList',
  components: {
    LPic
  },
  data() {
    return {

      list: [],//表格数据
      count: 1,//数据总量
      key: this.$store.state.app.activeApp.saa_key,
      limit: 10,
      page: 1,
      leader_name: '',
      begin_time: '',
      end_time: '',
      time: '',
      export_url: '',
    }
  },
  watch: {
    time(newTime) {
      if(newTime!==null){
        this.begin_time = parseTime(newTime[0],'{y}-{m}-{d} {h}:{i}:{s}');
        this.end_time = parseTime(newTime[1],'{y}-{m}-{d} {h}:{i}:{s}');
      }else{
        this.begin_time = '';
        this.end_time = '';
      }
    }
  },
  mounted() {
    this.getLeaderSales();
  },
  methods: {
    /**
     * 获取列表
     */
    getLeaderSales() {
      const params = { key: this.key, page: this.page, limit: this.limit };
      getLeaderSales(params).then(response => {
        if(response.status === 200){
          this.list = response.data;
          this.count = parseInt(response.count);
        }else if(response.status === 204){
          this.list = [];
          this.count = 1;
        }else{
          this.$message.error(response.message);
        }
      })
    },
    /**
     * 搜索
     */
    search() {
      this.params = {
        key: this.key,
        limit: 10,
        page: 1,
        leader_name: this.leader_name,
        begin_time: this.begin_time,
        end_time: this.end_time,
      }
      getLeaderSales(this.params).then(response => {
        if(response.status === 200){
          this.list = response.data;
          this.count = parseInt(response.count);
        }else if(response.status === 204){
          this.list = [];
          this.count = 1;
        }else{
          this.$message.error(response.message);
        }
      })
    },
    /**
     * 导出
     */
    export_data() {
      this.export_url = process.env.VUE_APP_BASE_API + '/leaderSalesExport?key=' + this.key + '&leader_name=' + this.leader_name + '&begin_time=' + this.begin_time + '&end_time=' + this.end_time
    },
    /**
     * 翻页
     */
    changePage(page) {
      this.page = page;
      this.getLeaderSales();
    }
  },
}
</script>

<style lang="scss" scoped>
.vip-list-container{
  min-height: calc(100vh - 100px);
  margin: 20px;
  background-color: #fff;
  padding:25px;
  box-shadow: 0px 0px 4px 0px rgba(115, 115, 115, 0.2);
}
.vip-list-top{
  margin: 20px auto;
  text-align: center;
  height: 40px;
  line-height: 40px;
  &-col{
    padding: 0 15px;
    max-width: 95%;
    overflow: hidden;
    display: flex;
    &>span{
      flex: 2;
      display: inline-block;
      padding: 0 5px;
      white-space: nowrap;
      overflow: hidden;
    }
    &>div{
      flex: 4
    }
  }
}
</style>
